package com.ruoyi.ai.controller;

import com.ruoyi.chatgpt.domain.GptChat;
import com.ruoyi.chatgpt.service.IGptChatService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * @description:ChatController
 * @author: caoes
 * create:2023/7/1 15:19
 **/
@Api(tags = "对话相关接口")
@RestController
@RequestMapping("/chat")
public class ChatController extends BaseController {

    @Autowired
    private IGptChatService gptChatService;

    @ApiOperation(value = "queryChatListPaging", notes = "分页查询聊天列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "页码", required = true, dataType = "Int", example = "1"),
            @ApiImplicitParam(name = "pageSize", value = "页数", required = true, dataType = "Int", example = "10")
    })
    @GetMapping(value = "list-paging")
    public TableDataInfo queryChatListPaging(int pageNo, int pageSize) {

        // 参数校验
        if (Objects.isNull(pageNo)) {
            throw new RuntimeException("页码不能为空");
        }
        if (Objects.isNull(pageSize)) {
            throw new RuntimeException("页数不能为空");
        }
        startPage();
        GptChat gptChat = new GptChat();
        gptChat.setUserId(SecurityUtils.getUserId());
        List<GptChat> list = gptChatService.selectGptChatList(gptChat);
        return getDataTable(list);
    }
    @ApiOperation(value = "queryChatList", notes = "查询聊天列表")
    @GetMapping(value = "list")
    public AjaxResult queryChatList() {
        GptChat gptChat = new GptChat();
        gptChat.setUserId(SecurityUtils.getUserId());
        List<GptChat> list = gptChatService.selectGptChatList(gptChat);
        return AjaxResult.success(list);
    }
}
